<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>不可变值</title>
    <script src='../node_modules/react/umd/react.development.js'></script>
    <script src='../node_modules/react-dom/umd/react-dom.development.js'></script>
    <script src='../node_modules/babel-standalone/babel.min.js'></script>
    <script src='../node_modules/prop-types/prop-types.js'></script>
</head>

<body>
    <div id='root'></div>
    <script type='text/babel'>
        class MyCom extends React.Component {
            constructor(props) {
                super(props)

                this.state = {
                    // arr的地址只能使用一次
                    arr: [1, 2, 3]
                }
            }

            render() {
                return (
                    <div>
                        <div>{this.state.arr}</div>

                        <button onClick={() => {
                            /* 实现方式0（不OK！！！） */
                            // this.state.arr.push(4)

                            /* 实现方式1 */
                            // this.setState({
                            //     arr: [...this.state.arr,4]
                            // })

                            /* 更多方式 */
                            // this.setState({
                            //     arr: this.state.arr.concat(4, [5, 6], 7, 8, 9)
                            // })

                        }}>add</button>
                    </div>
                )
            }
        }

        ReactDOM.render(<MyCom />, document.getElementById('root'))
    </script>
</body>

</html>